<template>
	<view>
		<!-- 一楼搜索框 -->
		<view class="header " style="position: fixed;top: 0; z-index: 10000;">

			<view class="d-flex" style="background-color: #29ad97;">
				<view class="search-input" @tap="search">
					<image src="@/static/img/index/sousuo1.png" mode="widthFix" style="width: 30rpx;"></image>
					<view class="">{{serchText}}</view>
				</view>
			</view>

		</view>
		<view class="left" style="">
			<view class="left-item" v-for="(item,index) in left" :key="index" :class="{active: index === currentindex}"
				@tap="change(index)">
				{{item.title}}
			</view>
		</view>
		<view class="" style="height: 250rpx;"></view>
		<view class="right">
			<view class="" style="height: 110px;">
				<image :src="right.icon" mode="" style="width: 94%;margin-left:3%;height:100%;border-radius: 10px;">
				</image>
			</view>

			<view class="" style="padding-bottom: 120upx;">
				<view class="" v-if="num > 0">
					<view v-for="(CPro) in right.lists" :key="CPro.id" class="center" style="width: 94%;margin-left:3%">
						<view class="item" @tap="godetail(CPro.id)"
							style="display: flex;flex-direction: row;height:80px;width: 100%;background-color: #fff;padding: 4px;border-radius: 4px;">
							<view class="item-left" style="width: 30%;height: 100%;">
								<image :src="CPro.goods_ico" mode="aspectFit" style="width: 100%;height: 100%;"></image>
							</view>
							<view class="item-right"
								style="display: flex;flex-direction: column;height: 100%;width: 70%;margin-left:10px">
								<view class="item-text" style="line-height: 45px;height: 45px;text-align: justify;">
									{{CPro.goods_name}}
								</view>
								<view class="item-introduct">
									{{CPro.goods_introduct}}
								</view>
								<view class="d-flex">
									<view class="flex-1 price" style="margin-left: 0;">￥{{CPro.member_price}} </view>
									<view class="sale sale1">已售{{CPro.sell_num}}</view>
									<view class="six  sale1"></view>
								</view>
							</view>

						</view>
					</view>
				</view>

				<view v-else
					style="color: #333;display: flex;line-height: 50px;height: 50px;align-items: center;width: 100%;justify-content: center;">
					<text>暂无数据...</text>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	export default {

		data() {
			return {
				serchText: '请输入关键字',
				left: [],
				currentindex: 0,
				cateId: 0,
				page: 1,
				loadingType: 'more', //加载更多状态
				totalCount: 0,
				right: [],
				num: 0,

			}
		},

		//下拉刷新
		onPullDownRefresh() {
			this.getCates()
			this.currentindex = 0;

			setTimeout(function() {
				uni.stopPullDownRefresh()
			}, 1000)
		},
		//加载更多
		// onReachBottom() {
		// 	this.getCatesProduts()
		// },

		onLoad() {
			this.getCates()
		},

		methods: {
			async getCates() {
				let Cates = await this.$myRequest({
					url: '/getCates'
				})

				this.left = Cates.data.data
				this.right = this.left[0];
				this.num = this.right.lists.length

			},

			change(index) {
				this.currentindex = index;
				this.right = this.left[index]
				this.num = this.right.lists.length
			},

			// async getCatesProduts(type = 'add') {
			// 	if (type === 'add') {
			// 		if (this.loadingType === 'nomore') {
			// 			return;
			// 		}
			// 		this.loadingType = 'loading';
			// 	} else {
			// 		this.page = 1;
			// 		this.loadingType = 'more'
			// 	}
			// 	let dataObj = {
			// 		page: this.page,
			// 		cate_id: this.cateId
			// 	}
			// 	let CatPro = await this.$myRequest({
			// 		url: "/getCatesProduts",
			// 		data: dataObj
			// 	})

			// 	if (CatPro.data.status == 1) {
			// 		let ndata = CatPro.data.data.list;
			// 		let count = CatPro.data.data.totalCount;
			// 		this.totalCount = count;

			// 		if (this.page === 1) {
			// 			this.reight = ndata;
			// 			if (ndata.length === 0) {
			// 				this.loadingType = 'nomore'
			// 			} else {
			// 				this.page = this.page + 1;
			// 			}
			// 		} else {
			// 			if (ndata.length === 0) {
			// 				this.loadingType = 'nomore'
			// 			} else {
			// 				this.reight = [...this.reight, ...ndata];
			// 				if (this.reight.length < this.totalCount) {
			// 					this.page = this.page + 1;
			// 				}
			// 			}
			// 		}

			// 		//判断是否还有下一页，有是more  没有是nomore(测试数据判断大于20就没有了)
			// 		this.loadingType = this.reight.length < this.totalCount ? 'more' : 'nomore';
			// 	}

			// 	if (type === 'refresh') {
			// 		setTimeout(function() {
			// 			uni.stopPullDownRefresh();
			// 		}, 500)
			// 	}
			// },

			chenked(index) {
				this.currentindex = index;
			},
			async initCateList() {
				this.getCates()
			},

			async godetail(id) {
				uni.navigateTo({
					url: '/pages/detail/detail?id=' + id
				})
			},
			async search() {
				uni.navigateTo({
					url: '/pages/index/HM-search'
				})
			},
		},
	}
</script>

<style lang="scss">
	.center {
		display: inline-flex;
		margin-top: 20rpx;
		margin-left: 15rpx;
	}

	.grid {
		background-color: white;
		width: 350rpx;
		height: 100%;
		border-radius: 20rpx;
	}

	.grid-image {
		width: 165rpx;
		height: 180rpx;
		margin: 70rpx 0 30rpx 100rpx;
	}

	.text {
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
		letter-spacing: 2rpx;
		word-break: normal;
		overflow: hidden;
		text-overflow: ellipsis;
		margin-top: 5rpx;
		margin-left: 15rpx;
		font-size: 28rpx;
	}

	.grid-text {
		color: #999;
		font-size: 24rpx;
		letter-spacing: 3rpx;
		margin: 10rpx 0 20rpx 15rpx;
	}

	.price {
		color: #29ad97;
		margin-left: 15rpx;
		margin-bottom: 10rpx;
	}

	.sale1 {
		font-size: 26rpx;
		letter-spacing: 3rpx;
		color: #999;
		margin-top: 5rpx;
	}

	.six {
		margin-left: 10rpx;
		margin-right: 25rpx;
	}

	page {
		background-color: #f5f5f5;
	}

	scroll-view ::-webkit-scrollbar {
		display: none;
	}

	.scroll {
		width: 100%;
		white-space: nowrap;
		border-bottom: 1px solid #fff;

		.tab-scroll_item {
			white-space: normal;
			display: inline-block;
			margin: 0 20rpx;
			padding: 10rpx 0;
		}

		& view:before {
			color: #f4f4f4;
			margin: 0 30rpx;
		}

		& view:first-child:before {
			display: none;
		}

	}

	.select {
		color: #29ad97;
		border-bottom: 4rpx solid #29ad97;
	}

	.list-item {
		overflow: hidden;
		height: 100%;
		width: 100%;

		.list {
			// float: left;
			width: 50%;
			height: 100%;
			margin: 20rpx 0 0 3%;
			border: 1rpx solid #eaeaea;
			background-color: #ffffff;
			border-radius: 12rpx;
		}
	}

	.header {
		background-color: white;
	}

	.search-input {
		background-color: #f8f8f8;
		width: 700rpx;
		height: 70rpx;
		margin: 100rpx 32rpx 20rpx 32rpx;
		border-radius: 10rpx;

		image {
			display: flex;
			margin: 20rpx 30rpx 0 20rpx;
		}

		view {
			font-size: 28rpx;
			color: #545556;
			margin-top: -35rpx;
			margin-left: 60rpx;

		}
	}

	.left {
		width: 160upx;
		position: absolute;
		top: 190upx;
		background-color: rgb(239, 240, 242);
		height: calc(100% - 190upx);
	}

	.left-item {
		font-size: 28upx;
		height: 70upx;
		line-height: 70upx;
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
		color: #333;
	}

	.active {
		background-color: #fff;
		color: #29ad97
	}

	.right {
		position: absolute;
		left: 160upx;
		width: calc(100% - 160upx);
		height: calc(100% - 190upx);
		top: 190upx;
	}

	.right-title {
		font-size: 30upx;
		color: #333;
		width: 100%;
		height: 70upx;
		line-height: 70upx;
		text-align: center;
		font-size: 30upx;
	}
</style>
